package base.mybatis.utils;

import javafx.beans.property.Property;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.util.Properties;

public class MyBatisUtil {
    private static SqlSessionFactory sessionFactory;
    private MyBatisUtil(){}

        static{
            try{
//                Properties p = new Properties();
//                p.load(Resources.getResourceAsStream("db.properties"));
                sessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis.cfg.xml"));
                } catch (IOException e) {
                e.printStackTrace();
            }
        }


    public static SqlSession getSqlSession(){
        return sessionFactory.openSession();
    }

}
